void drawsnake()
{
	int i;
	for (i = 0; i < snake.lenth; i++)
	{
		setlinecolor(LIGHTCYAN);
		fillrectangle(snake.xy[i].x, snake.xy[i].y, snake.xy[i].x + 10, snake.xy[i].y + 10);
	}

}

void SnakeMove()
{
	int i, j;
	for (i = snake.lenth - 1; i > 0; i--)
	{
		snake.xy[i].x = snake.xy[i - 1].x;
		snake.xy[i].y = snake.xy[i - 1].y;
	}
	switch (snake.position)
	{
	case sup:
		snake.xy[0].y -= 10;
		break;
	case sdown:
		snake.xy[0].y += 10;
		break;
	case sright:
		snake.xy[0].x += 10;
		break;
	case sleft:
		snake.xy[0].x -= 10;
		break;
	case paus:
		_getch();
		break;
	}
	while (_kbhit())
	{
		char key = _getch();

		switch (key)
		{
		case up:
			if (snake.position != sdown)
				snake.position = sup;
			break;
		case down:
			if (snake.position != sup)
				snake.position = sdown;
			break;
		case left:
			if (snake.position != sright)
				snake.position = sleft;
			break;
		case right:
			if (snake.position != sleft)
				snake.position = sright;
			break;
		case 'p':
			system("pause");
			break;
		}
	}
	Sleep(150);
	for (j = 2; j < snake.lenth; j++)
	{
		if (snake.xy[0].x == snake.xy[j].x && snake.xy[0].y == snake.xy[j].y)
			gameover();
	}
}

void grade()
{
	char player_grade[] = "当前分数";
	char grades[100];
	sprintf_s(grades, "%d", Food.grade);
	outtextxy(530, 100, player_grade);	
	outtextxy(530, 275, "操作说明");
	outtextxy(530, 300, "使用wasd操作");
	outtextxy(530, 325, "w往上走，s往下走");
	outtextxy(530, 350, "a往左走，d往右走");
	outtextxy(530, 375, "p键暂停,按任意键继续");
	outtextxy(635, 100, grades);

}

void speedup2()
{
	switch (Food.grade)
	{
	case 0: snake.speed = 30;
		outtextxy(50, 50, );
		break;
	case 10: snake.speed = 30;
		outtextxy(50, 50, );
		break;
	case 20: snake.speed = 30;
		outtextxy(50, 50, );
		break;
	case 30: snake.speed = 28;
		outtextxy(50, 50, );
		break;
	case 40: snake.speed = 28;
		outtextxy(50, 50, );
		break;
	case 50: snake.speed = 28;
		outtextxy(50, 50, );
		break;
	case 60: snake.speed = 28;
		outtextxy(50, 50, );
		break;
	case 70: snake.speed = 26;
		outtextxy(50, 50, );
		break;
	case 80: snake.speed = 26;
		outtextxy(50, 50, );
		break;
	case 90: snake.speed = 24;
		outtextxy(50, 50, );
		break;
	case 100:snake.speed = 24;
		outtextxy(50, 50, );
		break;
	case 110:snake.speed = 24;
		outtextxy(50, 50, );
		break;
	case 120:snake.speed = 24;
		outtextxy(50, 50, );
		break;
	case 130:snake.speed = 22;
		outtextxy(50, 50, );
		break;
	case 140:snake.speed = 22;
		outtextxy(50, 50, );
		break;
	case 150:snake.speed = 22;
		outtextxy(50, 50, );
		break;
	case 160:snake.speed = 22;
		outtextxy(50, 50, );
		break;
	default:snake.speed = 20;
		outtextxy(50, 50, );
		break;
	}
}
